package com.laxcen.intelligenttoy.BLE;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.laxcen.lib.CustomViewDialog;
import com.laxcen.toydemo.R;

public class BleConnectDialog extends CustomViewDialog implements View.OnClickListener {

    private static BleConnectDialog dialog;

    public static BleConnectDialog getInstance(Context context) {
        //双重锁模式，确保单例创建
        if (dialog == null) {
            synchronized (OpenBleProgreessDialog.class) {
                if (dialog == null) {
                    dialog = new BleConnectDialog(context);
                    dialog.setCancelable(false);
                    dialog.create();
                }
            }
        }
        return dialog;
    }

    private TextView txtvName, txtvSummary;
    private Button btnClose;

    public BleConnectDialog(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutViewId() {
        return R.layout.dialog_ble_connect;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }


    @Override
    protected void initViewControls() {
        super.initViewControls();
        txtvName = findViewById(R.id.txtvName);
        btnClose = findViewById(R.id.btnClose);
        if (btnClose != null) btnClose.setOnClickListener(this);
        //###2###，############
        setCancelableOnBackKey(false);
        setCancelable(true);
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btnClose) {
            dismiss();
        }
    }


    @Override
    protected void initViewDatas() {

    }

    @Override
    public synchronized void dismiss() {
        super.dismiss();
        dialog = null;
    }

    @Override
    public void show() {
        super.show();
    }


    public void show(String msg) {
        this.show();
        txtvName.setText(msg);
    }
}

